package com.googlecode.jpocketmod;

import com.googlecode.jpocketmod.templates.pages.PocketModPageInstance;
import java.awt.Frame;
import java.io.File;
import javax.swing.JOptionPane;

/**
 *
 * @author David Sosby
 */
public class DialogManager {
	private static DialogManager instance = new DialogManager();
	private Frame owner = null;
	
	private DialogManager()  {
	}
	
	public static DialogManager getInstance()  {  return instance;  }
	
	public void setDialogOwner(Frame owner)  {  this.owner = owner;  }
	
	public File showLoadTemplateDialog()  {
		TemplateFileChooser chooser = new TemplateFileChooser(owner);
		return chooser.getResult();
	}
	
	public File showSaveTemplateDialog()  {
		TemplateFileChooser chooser = new TemplateFileChooser(owner);
		chooser.setSaveDialog(true);
		
		File result = chooser.getResult();
		if ( !result.getName().endsWith(".jpmt") )  {
			result = new File(result.getAbsoluteFile() + ".jpmt");
		}
		
		return result;
	}
	
	public PocketModPageInstance showPageChooserDialog(PocketModPageInstance currentPage)  {
		JOptionPane.showMessageDialog(owner, "Choose a page");
		
		return currentPage;
	}
	
	public void showCreatePageDialog()  {
		CreatePageDialog dialog = new CreatePageDialog(owner);
		dialog.setVisible(true);
	}
}
